package by.euanpa.android.grodnobusstop.ui.bs.near;

import java.util.List;

import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import by.euanpa.android.grodnobusstop.bo.BusStop;
import by.euanpa.android.grodnobusstop.loader.BusStopLoader;
import by.euanpa.android.grodnobusstop.location.LocationHelper;
import by.euanpa.android.grodnobusstop.location.LocationListenerAdapter;

public class NearBusStopFragment extends ListFragment implements LoaderCallbacks<List<BusStop>> {


	private final LocationListenerAdapter locationListener = new LocationListenerAdapter() {
		public void onLocationChanged(Location location) {
			//TODO restart loader with new location;
		};
	};

	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		getLoaderManager().restartLoader(0, null, this);
	};
	
	@Override
	public void onResume() {
		requestCurrentLocation();
		super.onResume();
	}

	public void requestCurrentLocation() {
		LocationHelper.get(getActivity()).requestLocation(locationListener);
	}

	@Override
	public Loader<List<BusStop>> onCreateLoader(int id, Bundle data) {
		//TODO get location from data or in another way
		return new BusStopLoader(getActivity()) {
			@Override
			protected String getBusStopSelection() {
				//TODO create selection from db based on location
				return null;
			}
		};
	}

	@Override
	public void onLoadFinished(Loader<List<BusStop>> loader, List<BusStop> list) {
		//TODO set list to adapter
	}

	@Override
	public void onLoaderReset(Loader<List<BusStop>> loader) {
		//TODO clear adapter
	}
}